package com.yao.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 妖悲冥
 * @date 2021/5/5 0005   -    11:08
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 1. 对指定的路径模式启用跨域请求处理
     * 2. 允许跨域请求的来源列表
     * 3. 将HTTP方法设置为允许
     * 4. 浏览器是否应将凭据（例如Cookie和跨域请求）发送
     * 5. 响应缓存在时长
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("Http://localhost:8080", "null")
                .allowedMethods("GET", "POST", "PUT", "OPTIONS", "DELETE")
                .allowCredentials(true)
                .maxAge(3306);
    }
}
